home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / pppdump.c < prev    next >
C/C++ Source or Header  |  1994-06-04  |  3KB  |  161 lines

  1. /*
  2.  *    PPPDUMP.C
  3.  *
  4.  *    12-89    -- Katie Stevens (dkstevens@ucdavis.edu)
  5.  *           UC Davis, Computing Services
  6.  *    PPP.08    05-90    [ks] improve tracing reports
  7.  *    PPP.09  05-90    [ks] add UPAP packet reporting
  8.  *    PPP.14    08-90    [ks] change UPAP to PAP for consistency with RFC1172
  9.  *    PPP.15    09-90    [ks] update to KA9Q NOS v900828
  10.  *    Jan 91    [Bill Simpson] small changes to match rewrite of PPP
  11.  *    Aug 91    [Bill Simpson] fixed some buffer loss
  12.  */
  13. #include <stdio.h>
  14. #include "global.h"
  15. #include "mbuf.h"
  16. #include "iface.h"
  17. #include "internet.h"
  18. #include "ppp.h"
  19. #include "trace.h"
  20.  
  21. #ifdef TURBOC_SWITCH_BUG
  22. #pragma option -G-
  23. #endif
  24.  
  25. /* dump a PPP packet */
  26. void
  27. #ifdef MONITOR
  28. ppp_dump(fp,bpp,unused,mon)
  29. int mon;
  30. #else
  31. ppp_dump(fp,bpp,unused)
  32. #endif
  33. FILE *fp;
  34. struct mbuf **bpp;
  35. int unused;
  36. {
  37.     struct ppp_hdr hdr;
  38.     struct mbuf *tbp;
  39.  
  40. #ifdef MONITOR
  41.     if (mon)
  42.         fprintf(fp, "PPP ");
  43.     else
  44. #endif
  45.     fprintf(fp,"PPP: len %3u\t", len_p(*bpp));
  46.  
  47.     /* HDLC address and control fields may be compressed out */
  48.     if ((byte_t)(*bpp)->data[0] != HDLC_ALL_ADDR) {
  49. #ifdef MONITOR
  50.         if (!mon)
  51. #endif
  52.         fprintf(fp,"(compressed ALL/UI)\t");
  53.     } else if ((byte_t)(*bpp)->data[1] != HDLC_UI) {
  54. #ifdef MONITOR
  55.         if (!mon)
  56. #endif
  57.         fprintf(fp,"(missing UI!)\t");
  58.     } else {
  59.         /* skip address/control fields */
  60.         pull16(bpp);
  61.     }
  62.  
  63.     /* Initialize the expected header */
  64.     hdr.addr = HDLC_ALL_ADDR;
  65.     hdr.control = HDLC_UI;
  66.     hdr.protocol = PULLCHAR(bpp);
  67.  
  68.     /* First byte of PPP protocol field may be compressed out */
  69.     if ( hdr.protocol & 0x01 ) {
  70. #ifdef MONITOR
  71.         if (!mon)
  72. #endif
  73.         fprintf(fp,"compressed ");
  74.     } else {
  75.         hdr.protocol = (hdr.protocol << 8) | PULLCHAR(bpp);
  76.  
  77.         /* Second byte of PPP protocol field must be odd */
  78.         if ( !(hdr.protocol & 0x01) ) {
  79. #ifdef MONITOR
  80.         if (!mon)
  81. #endif
  82.             fprintf(fp, "(not odd!) " );
  83.         }
  84.     }
  85.  
  86. #ifdef MONITOR
  87.     if (!mon)
  88. #endif
  89.     fprintf(fp,"protocol: ");
  90.     switch(hdr.protocol){
  91.         case PPP_IP_PROTOCOL:
  92. #ifdef MONITOR
  93.         if (mon)
  94.         fprintf(fp, "IP ");
  95.         else
  96. #endif
  97.             fprintf(fp,"IP\n");
  98. #ifdef MONITOR
  99.             ip_dump(fp,bpp,1,mon);
  100. #else
  101.             ip_dump(fp,bpp,1);
  102. #endif
  103.             break;
  104.         case PPP_IPCP_PROTOCOL:
  105.             fprintf(fp,"IPCP\n");
  106.             break;
  107.         case PPP_LCP_PROTOCOL:
  108.             fprintf(fp,"LCP\n");
  109.             break;
  110.         case PPP_PAP_PROTOCOL:
  111.             fprintf(fp,"PAP\n");
  112.             break;
  113.         case PPP_COMPR_PROTOCOL:
  114. #ifdef MONITOR
  115.         if (mon)
  116.         fprintf(fp, "CSLIP ");
  117.         else
  118. #endif
  119.             fprintf(fp,"VJ Compressed TCP/IP\n");
  120. #ifdef MONITOR
  121.             vjcomp_dump(fp,bpp,0,mon);
  122. #else
  123.             vjcomp_dump(fp,bpp,0);
  124. #endif
  125.             break;
  126.         case PPP_UNCOMP_PROTOCOL:
  127. #ifdef MONITOR
  128.         if (mon)
  129.         fprintf(fp, "VJ ");
  130.         else
  131. #else
  132.             fprintf(fp,"VJ Uncompressed TCP/IP\n");
  133. #endif
  134.             /* Get our own copy so we can mess with the data */
  135.             if ( (tbp = copy_p(*bpp, len_p(*bpp))) == NULLBUF)
  136.                 return;
  137.  
  138. #ifdef MONITOR
  139.         if (!mon)
  140. #endif
  141.             fprintf(fp,"\tconnection 0x%02x\n",
  142.                 tbp->data[9]);        /* FIX THIS! */
  143.             /* Restore the bytes used with Uncompressed TCP */
  144.             tbp->data[9] = TCP_PTCL;    /* FIX THIS! */
  145. #ifdef MONITOR
  146.             ip_dump(fp,&tbp,1,mon);
  147. #else
  148.             ip_dump(fp,&tbp,1);
  149. #endif
  150.             free_p(tbp);
  151.             break;
  152.         default:
  153.             fprintf(fp,"unknown 0x%04x\n",hdr.protocol);
  154.             break;
  155.     }
  156. }
  157.  
  158. #ifdef TURBOC_SWITCH_BUG
  159. #pragma option -G
  160. #endif
  161.